package pers.liyan.shi.springcloud.mapper;

import org.apache.ibatis.annotations.*;
import pers.liyan.shi.springcloud.domain.Dept;

import java.util.List;

public interface DeptMapper {

    @Select("SELECT dept_no, dept_name, db_source from dept where dept_no = #{deptNo}")
    Dept findByNo(Long deptNo);

    @Select("SELECT dept_no, dept_name, db_source from dept")
    List<Dept> findAll();

    @Options(useGeneratedKeys = true, keyProperty = "deptNo")
    @Insert("INSERT INTO dept(dept_name,db_source) VALUES(#{deptName},DATABASE())")
    int addDept(Dept dept);

    @Update("update dept set dept_name = #{deptName} where dept_no = #{deptNo}")
    int updateByNo(Dept dept);

    @Delete("delete from dept where dept_no = #{deptNo}")
    int deleteByNo(Long deptNo);
}
